package com.epoint.rest;

import com.epoint.mapper.SpringBootUserMapper;
import com.epoint.mybatisplus.domain.Springbootuser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.configurationprocessor.json.JSONException;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class MybatisPlusRest {

    @Autowired
    private SpringBootUserMapper springBootUserMapper;

    @PostMapping("/getSpringbootUserById")
    public Map<String, Object> getSpringbootUserById(@RequestParam("params") JSONObject params) throws JSONException {
        Map<String, Object> mapParams = new HashMap<>();
        if(params.has("id") && !StringUtils.isEmpty(params.getString("id"))){
            mapParams.put("id", params.getString("id"));
        }
        if(params.has("name") && !StringUtils.isEmpty(params.getString("name"))){
            mapParams.put("name", params.getString("name"));
        }


        List<Springbootuser> users = springBootUserMapper.selectByMap(mapParams);

        Map<String, Object> result = new HashMap<>();
        Map<String, Object> custom = new HashMap<>();

        custom.put("users", users);
        result.put("status", "200");
        result.put("custom", custom);
        return result;
    }

}
